找传奇、传世资源到传世资源站!

pygame模块编钢琴

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

需要用到pygame模块按电脑上的1-8按键即可按下钢琴上的某个按键按esc或空格即可退出背景音乐为我的世界主题曲(zip文件里的"Minecraft-c418.mp3")pygame模块编钢琴 Python-第1张pygame模块编钢琴 Python-第2张pygame模块编钢琴 Python-第3张
import pygame,sys,timepygame.init()screen = pygame.display.set_mode((600, 400))pygame.display.set_caption("钢琴模拟")bgImg = pygame.image.load("piano.png")bgImg0 = pygame.image.load("piano.png")bgImg1 = pygame.image.load("piano1.png")bgImg2 = pygame.image.load("piano2.png")bgImg3 = pygame.image.load("piano3.png")bgImg4 = pygame.image.load("piano4.png")bgImg5 = pygame.image.load("piano5.png")bgImg6 = pygame.image.load("piano6.png")bgImg7 = pygame.image.load("piano7.png")bgImg8 = pygame.image.load("piano8.png")sound1 = pygame.mixer.Sound("1.wav")sound2 = pygame.mixer.Sound("2.wav")sound3 = pygame.mixer.Sound("3.wav")sound4 = pygame.mixer.Sound("4.wav")sound5 = pygame.mixer.Sound("5.wav")sound6 = pygame.mixer.Sound("6.wav")sound7 = pygame.mixer.Sound("7.wav")sound8 = pygame.mixer.Sound("8.wav")sound_big = 20pygame.mixer.music.load("Minecraft-c418.mp3")pygame.mixer.music.play(sound_big)run_thing = Truewhile run_thing: for event in pygame.event.get(): if event.type == pygame.QUIT or event.type == pygame.K_q: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_ESCAPE: run_thing = False elif event.key == pygame.K_1: bgImg = bgImg1 sound1.play() elif event.key == pygame.K_2: bgImg = bgImg2 sound2.play() elif event.key == pygame.K_3: bgImg = bgImg3 sound3.play() elif event.key == pygame.K_4: bgImg = bgImg4 sound4.play() elif event.key == pygame.K_5: bgImg = bgImg5 sound5.play() elif event.key == pygame.K_6: bgImg = bgImg6 sound6.play() elif event.key == pygame.K_7: bgImg = bgImg7 sound7.play() elif event.key == pygame.K_8: bgImg = bgImg8 sound8.play() elif event.key == pygame.K_0: sound_big -= 1 pygame.mixer.music.play(sound_big) screen.fill((255, 255, 255)) screen.blit(bgImg, (0, 0)) pygame.display.update() time.sleep(0.05) bgImg = bgImg0 screen.blit(bgImg, (0, 0)) pygame.display.update()

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复